home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE6 / PD / PDF / GuiLib / Task / h / GuiGadget next >
Text File  |  2003-02-14  |  9KB  |  231 lines

  1. //--------------------------------------------------------------------------
  2. //
  3. //   Copyright (c) 2002, Colin Granville
  4. //
  5. //   All rights reserved.
  6. //
  7. //   Redistribution and use in source and binary forms, with or
  8. //   without modification, are permitted provided that the following 
  9. //   conditions are met:
  10. //
  11. //      * Redistributions of source code must retain the above copyright 
  12. //        notice, this list of conditions and the following disclaimer.
  13. //
  14. //      * Redistributions in binary form must reproduce the above 
  15. //        copyright notice, this list of conditions and the following 
  16. //        disclaimer in the documentation and/or other materials 
  17. //        provided with the distribution.
  18. //
  19. //      * The name Colin Granville may not be used to endorse or promote 
  20. //        products derived from this software without specific prior 
  21. //        written permission.
  22. //
  23. //   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  24. //   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
  25. //   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
  26. //   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
  27. //   COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
  28. //   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  29. //   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  30. //   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
  31. //   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  32. //   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  33. //   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
  34. //   OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. //--------------------------------------------------------------------------
  37.  
  38. #ifndef GuiGadget_h
  39. #define GuiGadget_h
  40.  
  41. #include "GuiWindow.h"
  42.  
  43. void   set_component_string(GuiObjectId,GuiComponentId,int method_code,const char* str);
  44. string get_component_string(GuiObjectId,GuiComponentId,int method_code,int item=0);
  45. void   set_component_value(GuiObjectId ob_id,GuiComponentId comp_id,int method_code,int value);
  46. int    get_component_value(GuiObjectId ob_id,GuiComponentId comp_id,int method_code);
  47.  
  48. // GuiToolboxGadget generic flags
  49. #define GuiToolboxGadget_Faded   (1u<<31)
  50. #define GuiToolboxGadget_AtBack  (1u<<30)
  51.  
  52. class GuiToolboxGadget
  53. {
  54.   protected: // placed here so that they are inlined
  55.     int    getCompValue(int method_code) const
  56.                   {return get_component_value(m_window_id,m_component_id,method_code);}
  57.     void   setCompValue(int method_code,int value)
  58.                   {set_component_value(m_window_id,m_component_id,method_code,value);}
  59.     void   getCompStruct(int method_code,void* str) const
  60.                   {set_component_value(m_window_id,m_component_id,method_code,(int)str);}
  61.     void   setCompStruct(int method_code,const void* str)
  62.                   {set_component_value(m_window_id,m_component_id,method_code,(int)str);}
  63.     string getCompString(int method_code,int item=0) const
  64.                   {return get_component_string(m_window_id,m_component_id,method_code,item);}
  65.     void   setCompString(int method_code,const char* str)
  66.                   {set_component_string(m_window_id,m_component_id,method_code,str);}
  67.  
  68.   public:
  69.     enum {SwiChunkBase = 0x82880};
  70.     GuiToolboxGadget(GuiWindow& window, GuiComponentId cid);
  71.     unsigned int     getFlags() const                           {return getCompValue(64);}
  72.     void             setFlags(unsigned int new_flag_settings)   {setCompValue(65,new_flag_settings);}
  73.     void             fade(bool fade);
  74.                    
  75.     void             setHelpMessage(const char* message_text)   {setCompString(66,message_text);}
  76.     string           getHelpMessage() const                     {return getCompString(67);}
  77.     
  78.     void             setFocus()                                 {setCompValue(69,0);}
  79.     int              getType() const                            {return getCompValue(70);}
  80.     void             move(const GuiBBox& box)                      {setCompStruct(71,&box);}
  81.     void             getBBox(GuiBBox& box) const                   {getCompStruct(72,&box);}
  82.  
  83.     GuiObjectId      windowId() const                           {return m_window_id;}
  84.     GuiComponentId   componentId() const                        {return m_component_id;}
  85.     bool             contains(int wimp_handle,int icon_handle);
  86.  
  87.   private:
  88.     GuiObjectId    m_window_id;
  89.     GuiComponentId m_component_id;
  90.     
  91.     void operator=();                          //no copying - not defined
  92.     GuiToolboxGadget(const GuiToolboxGadget&); //no copying - not defined
  93. };
  94.  
  95. //*************************************************************************
  96. // GADGETS
  97. //*************************************************************************
  98.  
  99. class GuiActionButton : public GuiToolboxGadget
  100. {
  101.   public:
  102.     GuiActionButton(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
  103. };
  104.  
  105. //*************************************************************************
  106.  
  107. class GuiAdjuster : public GuiToolboxGadget
  108. {
  109.   public:
  110.     GuiAdjuster(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
  111.  
  112.     enum {Increment=1<<0,UpDown=1<<1}; //flags
  113.  
  114.     class Clicked : public GuiToolboxEventHeader
  115.     {
  116.       public:
  117.         enum {Event = GuiToolboxGadget::SwiChunkBase+12};
  118.         int        direction;
  119.         bool       isDown()    {return direction==0;}
  120.     };
  121. };
  122.  
  123. //*************************************************************************
  124.  
  125. class GuiButton : public GuiToolboxGadget
  126. {
  127.   public:
  128.     GuiButton(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
  129.  
  130.     void      setValue(const char* value)                   {setCompString(962,value);}
  131.  
  132. };
  133.  
  134. //*************************************************************************
  135.  
  136. class GuiDisplayField : public GuiToolboxGadget
  137.   public:
  138.     GuiDisplayField(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
  139.  
  140.     void        setValue(const char* value)    {setCompString(448,value);}
  141.     string      getValue() const               {return getCompString(449);}
  142. };
  143.  
  144. //*************************************************************************
  145.  
  146. class GuiLabel : public GuiToolboxGadget
  147. {
  148.   public:
  149.     GuiLabel(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
  150. };
  151.  
  152. //*************************************************************************
  153.  
  154. class GuiNumberRange : public GuiToolboxGadget
  155. {
  156.   public:
  157.     GuiNumberRange(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
  158.  
  159.     void setValue(int value)                       {setCompValue(832,value);}
  160.     int  getValue() const                          {return getCompValue(833);}
  161. };
  162.  
  163. //*************************************************************************
  164.  
  165. class GuiOptionButton : public GuiToolboxGadget
  166.   public:
  167.     GuiOptionButton(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
  168.  
  169.     void set(bool on)                               {setCompValue(196,(on)?1:0);}
  170.     bool isOn() const                               {return getCompValue(197);}
  171. };
  172.  
  173. //*************************************************************************
  174.  
  175. class GuiRadioButton : public GuiToolboxGadget
  176.   public:
  177.     GuiRadioButton(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
  178.  
  179.     void           select()                          {setCompValue(388,1);}
  180.     bool           isSelected() const                {return getCompValue(389);}
  181.     GuiComponentId getSelected() const;
  182. };
  183.  
  184. //*************************************************************************
  185.  
  186. class GuiSlider : public GuiToolboxGadget
  187.   public:
  188.     GuiSlider(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
  189.  
  190.     void setValue(int value)                     {setCompValue(576,value);}
  191.  
  192.     enum {SetUpper=1<<0,SetLower=1<<1,SetStepSize=1<<2};
  193.     void setBounds(int flags,int lower_bound,int upper_bound,int step_size);
  194.  
  195.     class ValueChanged : public GuiToolboxEventHeader
  196.     {
  197.       public:
  198.         enum {Event = GuiToolboxGadget::SwiChunkBase+6};
  199.         enum {DragStart=0,DragInProgress=2,DragEnded=1};//flags - different form book
  200.         int newValue;
  201.     };
  202. };
  203.  
  204. //*************************************************************************
  205.  
  206. class GuiToolAction : public GuiToolboxGadget
  207. {
  208.   public:
  209.     enum {SwiChunkBase=0x140140};
  210.     GuiToolAction(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {} 
  211.     void    set(bool on)                              {setCompValue(SwiChunkBase+6,(on)?1:0);}
  212. };
  213.  
  214. //*************************************************************************
  215.  
  216. class GuiWritableField : public GuiToolboxGadget
  217.   public:
  218.     GuiWritableField(GuiWindow& win, GuiComponentId cid) : GuiToolboxGadget(win,cid) {}
  219.     
  220.     void   setValue(const char* value)            {setCompString(512,value);}
  221.     string getValue() const                       {return getCompString(513);}
  222. };
  223.  
  224.  
  225. #endif
  226.